//
//  XJLeftTableViewCell.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/5/10.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJLeftTableViewCell.h"
#import "XJLeftTableModel.h"

@interface XJLeftTableViewCell()
@property (nonatomic, strong) UIView *bgView;

/**标题*/
@property(nonatomic, strong) UILabel *nameLb;
@end
@implementation XJLeftTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

#pragma mark - 一 lazy
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [UIView new];
        _bgView.backgroundColor = [UIColor whiteColor];
    }
    return _bgView;
}

- (UILabel *)nameLb {
    if (!_nameLb) {
        _nameLb = [UILabel new];
        _nameLb.layer.masksToBounds = YES;
        _nameLb.layer.cornerRadius = 5;
        _nameLb.textAlignment = NSTextAlignmentCenter;
        _nameLb.textColor = [UIColor lightGrayColor];
        _nameLb.font = XJFONTSET_R(13);
        _nameLb.backgroundColor = [UIColor whiteColor];
    }
    return _nameLb;
}
#pragma mark - 二 init
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        [self setupSubView];
    }
    return self;
}

- (void)setupSubView {
   
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.nameLb];
//    [self.contentView addSubview:self.nameLb];
}

#pragma mark - 三 layout
- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.bgView.backgroundColor = [UIColor whiteColor];
    self.bgView.sd_layout.leftSpaceToView(self.contentView, 5)
    .topSpaceToView(self.contentView, 5)
    .rightSpaceToView(self.contentView, 5)
    .bottomSpaceToView(self.contentView, 5);

    self.nameLb.sd_layout.topSpaceToView(self.bgView, 5).leftSpaceToView(self.bgView,6).rightSpaceToView(self.bgView,6).heightIs(ADAPTWidth(22));

//    self.nameLb.sd_layout.topSpaceToView(self.contentView, 5).leftSpaceToView(self.contentView,6).rightSpaceToView(self.contentView,6).heightIs(ADAPTWidth(22));
}

#pragma mark - 四 点击事件
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
//    选中之后让label文字加粗、变色
//self.nameLb.highlighted
    if (selected) {
        self.nameLb.backgroundColor = XJCOLOR_RGB(255, 218, 67);
        self.nameLb.textColor = [UIColor blackColor];
        self.nameLb.font = XJFONTSET_M(16);

    }else {
        self.nameLb.backgroundColor = [UIColor whiteColor];
        self.nameLb.textColor = [UIColor lightGrayColor];
        self.nameLb.font = XJFONTSET_R(13);;
    }
}

- (void)setModel:(XJLeftTableModel *)model{
    _model = model;
    self.nameLb.text = model.name;
    
}

@end
